﻿using SBlogCore.Common.JWTExtend.Models;
using SBlogCore.WebAdminApplication.LoginManager.IServices;

namespace SBlogCore.WebAdminApplication.LoginManager.Controllers
{
    /// <summary>
    /// 登录
    /// </summary>
    public class LoginController : UnAuthorizeBaseController
    {
        private readonly ILogService _logService;

        /// <summary>
        /// 构造函数
        /// </summary>
        public LoginController(ILogService logService)
        {
            this._logService = logService;
        }
        /// <summary>
        /// 登录并获取授权Token
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ResultEntity<TokenResultModel>> Login(UserLoginInput input)
        {

            var res=await _logService.Login(input.account,input.password);
            return Success(res);
        }
        /// <summary>
        /// 刷新Token
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultEntity<TokenResultModel>> RefreshToken()
        {
            var token = GetToken();
            var res = await _logService.RefreshToken(token);
            return Success(res);
        }
    }
}
